package pkg

import (
	"io"
	"net/http"
	"net/url"
	"strings"

	"192.168.1.75/go-pkg/errorx"
)

func PostFormURLEncoded(url string, data url.Values) (res []byte, err error) {
	resp, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
	if err != nil {
		return res, errorx.New("请求失败", -1)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return res, errorx.New(err.Error(), -1)
	}
	return body, err
}
